# -*- coding: utf-8 -*-
# @Author	: changfeng
# @Date		: 2025/9/12 11:58
# @Last Modified by:   changfeng
# @Last Modified time: 2025/9/12 11:58
# Thanks for your comments!

import json
from quart import Blueprint, request, Response

from src.basedata.common.dep_manage import ENVIRONMENT
from src.basedata.interfaces.assembler.request_param import handle_common

sync_bs_bp = Blueprint('sync_bs_bp', __name__)


@sync_bs_bp.route("/department", methods=['POST', "GET"])
async def sync_department_data():
    if request.method == 'POST':
        params = await request.get_json(force=True)
    else:
        params = request.args.to_dict()

    bus = ENVIRONMENT.get_dependencies('bus')
    response = await handle_common({'bizCode': 'sync_app_department_basedata', 'data': params},
                                   bus)
    return Response(json.dumps(response.serialize_to_dict(), ensure_ascii=False))


@sync_bs_bp.route("/person", methods=['POST', "GET"])
async def sync_person_data():
    if request.method == 'POST':
        params = await request.get_json(force=True)
    else:
        params = request.args.to_dict()

    bus = ENVIRONMENT.get_dependencies('bus')
    response = await handle_common({'bizCode': 'sync_app_person_basedata', 'data': params},
                                   bus)
    return Response(json.dumps(response.serialize_to_dict(), ensure_ascii=False))


@sync_bs_bp.route("/medicine", methods=['POST', "GET"])
async def sync_medicine_data():
    if request.method == 'POST':
        params = await request.get_json(force=True)
    else:
        params = request.args.to_dict()

    bus = ENVIRONMENT.get_dependencies('bus')
    response = await handle_common({'bizCode': 'sync_app_medicine_basedata', 'data': params},
                                   bus)
    return Response(json.dumps(response.serialize_to_dict(), ensure_ascii=False))


@sync_bs_bp.route("/administration_router", methods=['POST', "GET"])
async def sync_administration_router_data():
    if request.method == 'POST':
        params = await request.get_json(force=True)
    else:
        params = request.args.to_dict()

    bus = ENVIRONMENT.get_dependencies('bus')
    response = await handle_common({'bizCode': 'sync_app_route_of_administration_basedata', 'data': params},
                                   bus)
    return Response(json.dumps(response.serialize_to_dict(), ensure_ascii=False))


@sync_bs_bp.route("/frequency", methods=['POST', "GET"])
async def sync_frequency_data():
    if request.method == 'POST':
        params = await request.get_json(force=True)
    else:
        params = request.args.to_dict()

    bus = ENVIRONMENT.get_dependencies('bus')
    response = await handle_common({'bizCode': 'sync_app_administration_freq_basedata', 'data': params},
                                   bus)
    return Response(json.dumps(response.serialize_to_dict(), ensure_ascii=False))


@sync_bs_bp.route("/icd_code", methods=['POST', "GET"])
async def sync_icd_code_data():
    if request.method == 'POST':
        params = await request.get_json(force=True)
    else:
        params = request.args.to_dict()

    bus = ENVIRONMENT.get_dependencies('bus')
    response = await handle_common({'bizCode': 'sync_app_disease_code_basedata', 'data': params},
                                   bus)
    return Response(json.dumps(response.serialize_to_dict(), ensure_ascii=False))
